home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************
-
- Sound101_main.c
-
- © 1992 Praxitel, Inc. and Iggi Monahelis
-
- This is the "main" for the Sound 101 project. It has the minimum stuff to get a mac
- program going. Basically, it does all the required mac initializations, sets up the menu
- bar, and then gets and processes events.
-
- *************************************************************************************/
- #include "Sound101.h"
-
-
- extern int gDestroyChannel;
- extern SndChannelPtr gSndChan;
- extern short gFRefNum;
- extern long gQuality;
-
- /************************************************************************************
-
- main
-
- This is the main routine for the Sound 101 application, it does all the Mac initializations.
- Then calls the EventLoop procedure to get and process events.
-
- *************************************************************************************/
- void main(void)
- {
- InitGraf((Ptr) &thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- MaxApplZone();
- SetUpMenus();
-
- EventLoop(); /* Do event processing until user quits */
-
- }
-
-
- /************************************************************************************
-
- SetUpMenus
-
- Set up the menu bar for the Sound 101 application
-
- *************************************************************************************/
- void SetUpMenus(void)
- {
- MenuHandle myMenu;
-
- myMenu = GetMenu(mApple);
-
- AddResMenu( myMenu, 'DRVR' );
- InsertMenu( myMenu, 0 );
- InsertMenu(GetMenu(mFile), 0) ;
- DrawMenuBar();
- }
-
- /************************************************************************************
-
- EventLoop
-
- Event handling for the Sound 101 application.
- Get events forever, and handle them by calling DoEvent.
-
- ************************************************************************************/
- void EventLoop(void)
- {
- Boolean gotEvent;
- EventRecord event;
-
- do {
- gotEvent = WaitNextEvent(everyEvent, &event, 50, 0);
- if ( gotEvent ) {
- DoEvent(&event);
- }
- /* if we are done with the sound, dispose the sound channel and close
- the sound file.
- */
- if ( gDestroyChannel ) {
- OSErr myErr;
-
- InitCursor();
- if (gSndChan)
- myErr = SndDisposeChannel( gSndChan, TRUE);
- if (gFRefNum)
- myErr = FSClose(gFRefNum);
- /* make sure we do it only once! */
- gDestroyChannel = FALSE;
- gSndChan = 0;
- gFRefNum = 0;
- }
- } while ( true ); /* loop forever */
- } /*EventLoop*/
-
- /************************************************************************************
-
- DoEvent
-
- Determine the event type and dispatch accordingly
-
- ************************************************************************************/
- void DoEvent(EventRecord *event)
- {
- short part, err;
- WindowPtr window;
- char key;
-
- switch ( event->what ) {
- case nullEvent:
- break;
- case mouseDown:
- part = FindWindow(event->where, &window);
- switch ( part ) {
- case inMenuBar: /* process a mouse menu command */
- DoMenuCommand(MenuSelect(event->where));
- break;
- case inSysWindow: /* let the system handle the mouseDown */
- SystemClick(event, window);
- break;
- case inContent:
- break;
- case inDrag:
- break;
- case inGoAway:
- break;
- case inGrow:
- break;
- case inZoomIn:
- case inZoomOut:
- break;
- }
- break;
- case keyDown:
- case autoKey: /* check for menukey equivalents */
- key = event->message & charCodeMask;
- if ( event->modifiers & cmdKey ) { /* Command key down */
- /* if command-period was pressed, set our global to clean up
- the sound channel and close the open sound file
- */
- if ( key == '.' )
- gDestroyChannel = TRUE; /* command period was pressed */
-
- }
- break;
- case activateEvt:
- break;
- case updateEvt:
- break;
- }
- } /*DoEvent*/
-
- /************************************************************************************
-
- DoMenuCommand
-
- Handles menu selections for the Sound 101 application
-
- ************************************************************************************/
- void DoMenuCommand(long menuResult)
- {
- short menuID, menuItem;
- short itemHit, daRefNum;
- Str255 daName;
-
- menuID = HiWord(menuResult);
- menuItem = LoWord(menuResult);
- switch ( menuID ) {
- case mApple:
- switch ( menuItem ) {
- case iAbout: { /* bring up the About box */
- OSErr err;
- GrafPtr oldPort;
- Rect tempRect;
- DialogPtr aboutDlg;
-
- GetPort(&oldPort);
-
- aboutDlg = GetNewDialog(128, nil, (WindowPtr) -1);
- if ( aboutDlg ) {
- ShowWindow(aboutDlg); /* Open a dialog box */
- SelectWindow(aboutDlg); /* Lets see it */
- SetPort(aboutDlg);
- while (TRUE) {
- ModalDialog(NULL, &itemHit);
- if ( itemHit == 1 )
- break;
- }
- DisposDialog(aboutDlg);
- SetPort(oldPort);
- }
- }
- break;
-
- default: /* all non-About items in this menu are DAs */
- GetItem(GetMHandle(mApple), menuItem, daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
-
- case mFile:
- switch ( menuItem ) {
- case iPlaySound:
- PlayASound();
- break;
- case iRecordsndSound:
- Record_snd_resource(gQuality);
- break;
- case iRecordAIFFSound:
- Record_AIFF_sound(gQuality);
- break;
- case iQuality:
- GetQuality();
- break;
- case iQuit:
- Terminate();
- break;
- }
- break;
- }
-
- HiliteMenu(0); /* unhighlight what MenuSelect (or MenuKey) hilited */
- }
-
- /************************************************************************************
-
- Terminate
-
- Quit the app
-
- ************************************************************************************/
- void Terminate(void)
- {
- ExitToShell(); /* exit if no cancellation */
- } /*Terminate*/
-